/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Chart;

import java.util.ArrayList;
import java.util.List;
import me.aviator.entity.Ribbon;
import org.w3c.dom.Element;
import org.w3c.dom.svg.SVGDocument;

/**
 *
 * @author Administrator
 */
public class BarChart extends SvgChart{
    private List<String> Lable;//标签，每个扇形区域代表的意义
    private List<Double> dataset;//原始制图数据
    private List<String> barfract;//生成的条形区图
    private Ribbon ribbon;
    private String chartName;
    private String Xaxis;
    private String Yaxis;
    
    public BarChart(){
    }
    
    public BarChart(String name,List<String> lable,List<Double> dataset, Ribbon r){
        chartName=name;
        this.Lable=lable;
        this.dataset=dataset;
        ribbon=r;
    }
    
    public void setBarfract(ArrayList<String> barfract){
        this.barfract=barfract;
    }
    
    public void setXaxis(String Xaxis){
        this.Xaxis=Xaxis;
    }
    
    public void setYaxis(String Yaxis){
        this.Yaxis=Yaxis;
    }
    
    @Override
    public void draw(Element root,SVGDocument doc){
        Element group=doc.createElement("g");
        if(chartName!=null)
        {
            group.setAttribute("id", chartName);
        }
        Element e1=doc.createElement("path");
        e1.setAttribute("d", Xaxis);
        //e1.setAttribute("fill", "rbg(0,255,0)");
        group.appendChild(e1);
        Element ey=doc.createElement("path");
        ey.setAttribute("d", Yaxis);
        //ey.setAttribute("fill", "rgb(0,255,0)");
        group.appendChild(ey);
        for(int i=0;i<barfract.size();i++){
            Element e=doc.createElement("path");
            if(Lable!=null&&!Lable.isEmpty())
            {
                e.setAttribute("id", Lable.get(i));
            }
            e.setAttribute("d", barfract.get(i));
            e.setAttribute("fill", "rgb("+String.format("%d,%d,%d",ribbon.getColorlist().get(i).getRed(),ribbon.getColorlist().get(i).getGreen(),ribbon.getColorlist().get(i).getBlue())+")");
            group.appendChild(e);
        }
        root.appendChild(group);
    }
}
